package com.yxh.bigdata.mapreduce.test.flowsum;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, FlowWritable, Text, FlowWritable> {

    @Override
    protected void reduce(Text key, Iterable<FlowWritable> values, Context context) throws IOException, InterruptedException {
        long upSum = 0;
        long downSum = 0;

        for(FlowWritable flow : values){
            upSum += flow.getUpFlow();
            downSum += flow.getDownFlow();
        }
        context.write(key, new FlowWritable(upSum, downSum));
    }
}
